/*
 * Copyright (C) 2011, 2012 Moravská zemská knihovna v Brně / Moravian Library in Brno
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.mzk.oai.provider.tools;

import cz.mzk.oai.metadataRepository.metadata.MetadataFormat;
import cz.mzk.oai.metadataRepository.repository.Identifier;
import cz.mzk.oai.provider.ErrorCode;
import cz.mzk.oai.provider.OaiException;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public class Parser {

    public static MetadataFormat parseMetadataPrefix(String metadataPrefix) throws OaiException {
        try {
            return MetadataFormat.parseString(metadataPrefix);
        } catch (Throwable e) {
            throw new OaiException(ErrorCode.cannotDisseminateFormat, "Invalid metadata prefix '" + metadataPrefix + "'");
        }
    }

    public static Identifier parseIdentifier(String idString) throws OaiException {
        try {
            return Identifier.parseNotEncodedString(idString);
        } catch (Throwable e) {
            throw new OaiException(ErrorCode.idDoesNotExist, "Invalid identifier '" + idString + "'");
        }
    }
}
